package com.example.mobile2021606170hsy0406homework;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class Main9Activity extends AppCompatActivity {

    private TextView tvMainTitle8;
    private TextView tvMain82;
    private TextView tvLirun;
    private EditText edtTxtMainLirun;
    private Button btMainJiaoji;
    private TextView tvMainResult;
    double bonus, bon1, bon2, bon4, bon6, bon10;
    private TextView tvMain83;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main9);
        initView();
        bon1 = 100000 * 0.1;
        bon2 = bon1 + 100000 * 0.075;
        bon4 = bon2 + 100000 * 0.05;
        bon6 = bon4 + 100000 * 0.03;
        bon10 = bon6 + 100000 * 0.015;
    }

    private void initView() {
        tvMainTitle8 = findViewById(R.id.tv_main_title8);
        tvMain82 = findViewById(R.id.tv_main_8_2);
        tvLirun = findViewById(R.id.tv_lirun);
        edtTxtMainLirun = findViewById(R.id.edtTxt_main_lirun);
        btMainJiaoji = findViewById(R.id.bt_main_jiaoji);
        tvMain83 = findViewById(R.id.tv_main_8_3);
    }

    public void jisuanonClick(View view) {
        String a = edtTxtMainLirun.getText().toString();
        if (a.length() == 0) {
            Toast.makeText(Main9Activity.this, "请输入数字", Toast.LENGTH_SHORT).show();
        } else {
            double b = Double.parseDouble(a);
            if (b <= 100000) {
                bonus = b * 0.1;
                tvMainResult.setText(String.valueOf(bonus));
            } else if (b <= 200000) {
                bonus = bon1 + (b - 100000) * 0.075;
                tvMainResult.setText(String.valueOf(bonus));
            } else if (b <= 400000) {
                bonus = bon2 + (b - 200000) * 0.05;
                tvMainResult.setText(String.valueOf(bonus));
            } else if (b <= 600000) {
                bonus = bon4 + (b - 400000) * 0.03;
                tvMainResult.setText(String.valueOf(bonus));
            } else if (b <= 1000000) {
                bonus = bon6 + (b - 600000) * 0.015;
                tvMainResult.setText(String.valueOf(bonus));
            } else {
                bonus = bon10 + (b - 1000000) * 0.01;
                tvMainResult.setText(String.valueOf(bonus));

            }
        }
    }
}

